Page({
  data: {
    labs: ['差评', '吐槽', '中评', '很棒', '好评'],
    score: 5,
    imgList: [],
    imgCount: 6,
    content: '',
    maxlength: 200,
    inputLength: 0,
    isAnonymous: true,
    uploadUrl: wx.util.interfaceUrl('common.upload.images')['url']
  },
  onLoad: function (options) {
    this.setData({
      id: options.id,
      img: options.img,
      evaluate: (options.evaluate == 1)
    });
  },
  change: function (e) {
    this.setData({
      score: e.detail.index
    });
  },
  userInput: function (e) {
    this.setData({
      content: e.detail.value,
      inputLength: e.detail.value.length
    });
  },
  imgUpload: function (e) {
    if (e.detail.status === 1) {
      this.setData({
        imgList: e.detail.imgArr
      });
    }
  },
  anonymous: function (e) {
    this.setData({
      isAnonymous: (e.detail.value[0] == 1)
    });
  },
  evaluate: function () {
    wx.util.request(`order.evaluate.${this.data.evaluate ? 'again' : 'new'}`, {
      query: `order_product_id=${this.data.id}`,
      body: {
        evaluate: JSON.stringify([
          {
            order_product_id: this.data.id,
            scores: this.data.score,
            covers: this.data.imgList,
            is_anonymous: this.data.isAnonymous ? 1 : 0,
            content: this.data.content
          }
        ]),
        again_content: this.data.content,
        again_covers: JSON.stringify(this.data.imgList)
      }
    }).then(() => {
      wx.util.toast('感谢您本次的评价');
      setTimeout(() => {
        wx.navigateBack();
      }, 1500);
    });
  }
})